<?php

    $username = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];

    require( 'mysqli_connect.php' );

    $query = "INSERT INTO user (`username`, `password`, `email`, `enabled`, `lastlogin`) VALUES ('" . $username . "', '" . $password . "', '" . $email . "', 1, NOW() )";

    mysqli_query($dbc, $query);
    
    $affected_rows = mysqli_affected_rows($dbc);

    if ( $affected_rows ==1 ){
       header('Location:index.php'); // registratie geslaagd 
    } else {
       header('Location:register.php?error=true'); // registratie mislukt, username of emailadres bestaat reeds.
    }   
?>
